<?php
declare (strict_types=1);

namespace app\index\controller;

use app\common\model\UserNotify;
use app\common\tool\Result;
use think\facade\View;
use think\Response;

class Notify extends Base
{
    public function index(): string
    {
        return View::fetch();
    }

    public function getList(): Response
    {
        $map = ['uid' => $this->user->id];

        return Result::fastReturn(UserNotify::getPageList($map, 'id,title,create_time',
            $this->getPage(), $this->getLimit(), false));
    }

    public function details($id): string|Response
    {
        $info = UserNotify::where(['id' => $id])->find();
        if (!$info) {
            return redirect('/');
        }
        if ($info->status == 0) {
            $info->status = 1;
            $info->save();
        }
        View::assign('info', $info);

        return View::fetch();
    }
}